package ru.belokuriha_online.resort_hotels_belokuriha;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.lang.CharSequence;
import java.net.HttpURLConnection;
import java.net.URL;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import com.google.android.gms.ads.*; //vrem

import android.app.Activity;
import android.app.AlertDialog;

import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Events;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;

import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SimpleExpandableListAdapter;
import android.widget.Toast;
import android.view.*;
import android.net.*;
import android.widget.*;
import android.content.*;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.TransitionDrawable;

public class Mainprice extends Activity {

	public static File EDIR = Environment.getExternalStorageDirectory();	
	String filepricesPath;	

	Integer flagdata;
	Integer i;
	Integer k;
	String groupa1;
	String groupa2;
	String ssanatori_name;
	String iid_name;
	String ssanatori_name1;
	String iid_name1;
	String sanprice_period;
	String spprisepath;
	String spprisepathfull;
	String str_san_phone;
	String str_san_map;
	int FlagOnlain;
	HttpURLConnection urlConnectiond;
	XmlPullParser parserxml;
	InputStream xmlfiles;

	ArrayList<HashMap<String, String>> groupData;
	
	ArrayList<HashMap<String, String>> childDataItem;
	ArrayList<ArrayList<HashMap<String, String>>> childData;
	HashMap<String, String> m;
	HashMap<String, String> n;


	ExpandableListView listt;
	View Header1;
	View Footer1;
	Integer flags_srav;
	String mpp_1,mpp_2,mpp_3,mpp_4,mpp_5,mpp_6;
	String msp_1,msp_2,msp_3,msp_4,msp_5,msp_6;
	Integer indexGX,indexGXs,indexIX,indexIXs;
	final int next_srav_id = 1;
	//SimpleExpandableListAdapter adapterpr;
	PriceAdapter MyAdapterpr;
	String msp_0,msp_0_0;
	Integer gpos,childpos;
	Integer flaglockother;
	View viewitem;

	private CharSequence[] spisok;
	AlertDialog.Builder buildergosrav;

	private CharSequence[] dopmenu;
	AlertDialog.Builder dialogdopmenu;
	TextView footersan_phone;
	TextView footersan_map;
	View footersan_phone_d;
	View footersan_map_d;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainprice);
		try {
			
		
		dopmenu = getResources().getTextArray(R.array.dopmenu);
		flags_srav = 0;
		flaglockother = 0;
		spisok = getResources().getTextArray(R.array.menupr);
		ssanatori_name = getIntent().getExtras().getString("san_name");
		iid_name = getIntent().getExtras().getString("id_name");
		spprisepath = getIntent().getExtras().getString("spprisepath");
		spprisepathfull = getIntent().getExtras().getString("spprisepathfull");
		FlagOnlain = getIntent().getExtras().getInt("FlagOnlain");
		flags_srav = getIntent().getExtras().getInt("flags_srav");
		if (flags_srav == 1) {
			//
			mpp_1 = getIntent().getExtras().getString("mpp_1");
			mpp_2 = getIntent().getExtras().getString("mpp_2");
			mpp_3 = getIntent().getExtras().getString("mpp_3");
			mpp_4 = getIntent().getExtras().getString("mpp_4");
			mpp_5 = getIntent().getExtras().getString("mpp_5");
			mpp_6 = getIntent().getExtras().getString("mpp_6");
		}
		LinearLayout panell = (LinearLayout) findViewById(R.id.panel2);
		LayoutInflater panellInflater = getLayoutInflater();
		View panellorg = panellInflater.inflate(R.layout.panel, panell, true);
		
		
		LinearLayout reklama = (LinearLayout) findViewById(R.id.reklamagoo2);
		LayoutInflater reklamaInflater = getLayoutInflater();
		try {
			View reklamaorg = reklamaInflater.inflate(R.layout.reklamagoo, reklama, true);
			AdView adView = (AdView)reklamaorg.findViewById(R.id.adView); //vremenno
			AdRequest adRequest = new AdRequest.Builder().build();
			adView.loadAd(adRequest); //vrem
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		TextView dataTextView = (TextView)findViewById(R.id.textView3);
		dataTextView.setText(ssanatori_name);
		//listpriceHandler();
		listprice_();
		


		///

		final ImageButton zv1 =(ImageButton) panellorg.findViewById(R.id.imageButton1);
		zv1.setOnClickListener(new View.OnClickListener() {
			TransitionDrawable TelfTransition = (TransitionDrawable)getApplicationContext().getResources().getDrawable(R.drawable.transition_telef);	
			public void onClick(View v) {
				try {
					zv1.setImageDrawable(TelfTransition);
					TelfTransition.startTransition(1000);
					String stel = getString(R.string.telefonmob);
					Intent diallintent = new Intent(Intent.ACTION_DIAL,Uri.parse(stel));
					startActivity(diallintent);
				} catch (Exception e) {

				}
			}	
		});

		final ImageButton eml =(ImageButton) panellorg.findViewById(R.id.imageButton2);
		eml.setOnClickListener(new View.OnClickListener() {
			TransitionDrawable EmlTransition = (TransitionDrawable)getApplicationContext().getResources().getDrawable(R.drawable.transition_eml);
			public void onClick(View v) {
				try {
					eml.setImageDrawable(EmlTransition);
					EmlTransition.startTransition(1000);
					String smail = getString(R.string.email);
					Intent emalintent = new Intent(Intent.ACTION_VIEW,Uri.parse(smail));
					startActivity(emalintent);
				} catch (Exception e) {

				}	
			}	
		});
		final ImageButton abt =(ImageButton) panellorg.findViewById(R.id.imageButton4);
		abt.setOnClickListener(new View.OnClickListener() {
			TransitionDrawable AboutTransition = (TransitionDrawable)getApplicationContext().getResources().getDrawable(R.drawable.transition_about);
			public void onClick(View v) {
				try {
					abt.setImageDrawable(AboutTransition);
					AboutTransition.startTransition(1000);
					Intent intentab = new Intent(getApplicationContext(), About.class);
					intentab.putExtra("spprisepath", spprisepath);
					intentab.putExtra("FlagOnlain", FlagOnlain);
					startActivityForResult(intentab,0);
				} catch (Exception e) {

				}
			}	
		});
		final ImageButton brouz =(ImageButton) panellorg.findViewById(R.id.imageButton5);
		brouz.setVisibility(View.GONE); 
		/*brouz.setOnClickListener(new View.OnClickListener() {
			TransitionDrawable BrTransition = (TransitionDrawable)getApplicationContext().getResources().getDrawable(R.drawable.transition_browser);
			public void onClick(View v) {
				try {
					brouz.setImageDrawable(BrTransition);
					BrTransition.startTransition(1000);
					String sweb = getString(R.string.web);
					Intent brouzintent = new Intent(Intent.ACTION_VIEW,Uri.parse(sweb));
					startActivity(brouzintent);
				} catch (Exception e) {

				}

			}	
		});
		*/
		final ImageButton favoritsActiv =(ImageButton) panellorg.findViewById(R.id.imageButtonfavoritsactiv);
		favoritsActiv.setVisibility(View.VISIBLE); 
		favoritsActiv.setOnClickListener(new View.OnClickListener() {
		TransitionDrawable favTransition = (TransitionDrawable)getApplicationContext().getResources().getDrawable(R.drawable.transition_favorits);	
			public void onClick(View v) {
				try {
					favoritsActiv.setImageDrawable(favTransition);
					favTransition.startTransition(1000);
					Intent intentfavoris = new Intent(getApplicationContext(), Favorits.class);
					intentfavoris.putExtra("spprisepath", spprisepath);
					intentfavoris.putExtra("spprisepathfull", spprisepathfull);
					intentfavoris.putExtra("FlagOnlain", FlagOnlain);
					startActivityForResult(intentfavoris,3);
					
				} catch (Exception e) {

				}

			}	
		});


		final ImageButton homes =(ImageButton) panellorg.findViewById(R.id.imageButton3);
		homes.setOnClickListener(new View.OnClickListener() {
			TransitionDrawable HomTransition = (TransitionDrawable)getApplicationContext().getResources().getDrawable(R.drawable.transition_hom);
			public void onClick(View v) {
				try {
					homes.setImageDrawable(HomTransition);
					HomTransition.startTransition(1000);
					finish();
				} catch (Exception e) {

				}

			}	
		});
		homes.setOnLongClickListener(new View.OnLongClickListener() {
			TransitionDrawable HomTransition = (TransitionDrawable)getApplicationContext().getResources().getDrawable(R.drawable.transition_hom);	
			@Override
			public boolean onLongClick(View v) {
				homes.setImageDrawable(HomTransition);
				HomTransition.startTransition(1000);
					Dopmenu();
				return false;
			}
		});
		final ImageButton srav =(ImageButton) panellorg.findViewById(R.id.imageButtonsrav);
		srav.setOnClickListener(new View.OnClickListener() {
			TransitionDrawable sravTransition = (TransitionDrawable)getApplicationContext().getResources().getDrawable(R.drawable.transition_compare);
			public void onClick(View v) {
				try {
					srav.setImageDrawable(sravTransition);
					sravTransition.startTransition(1000);
					Intent intentsea = new Intent(getApplicationContext(), Sravneniye.class);
					if (groupData.size() >0) {
					intentsea.putExtra("san_name", ssanatori_name);
					intentsea.putExtra("id_name", iid_name);
					intentsea.putExtra("spprisepath", spprisepath);
					intentsea.putExtra("spprisepathfull", spprisepathfull);
					intentsea.putExtra("FlagOnlain", FlagOnlain);
					Integer flags_srav = 3;
					intentsea.putExtra("flags_srav", flags_srav);					
					startActivityForResult(intentsea,3);
					}
				} catch (Exception e) {

				}
			}	
		});
		
		final TextView footerTextView1 = (TextView)findViewById(R.id.tpView1);
		footerTextView1.setText(R.string.footer_price);
		footerTextView1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				try {
					Intent intent = new Intent(getApplicationContext(),AboutSanator.class);

					String sanatori_name1 = getIntent().getExtras().getString("san_name");
					String idd_name1 = getIntent().getExtras().getString("id_name");
					intent.putExtra("san_name1", sanatori_name1);
					intent.putExtra("id_name1", idd_name1);
					intent.putExtra("spprisepath", spprisepath);
					intent.putExtra("spprisepathfull", spprisepathfull);
					intent.putExtra("FlagOnlain", FlagOnlain);
					startActivityForResult(intent, 3);
				} catch (Exception e) {

				}

			}	
		});	
		
		
		///
	} catch (Exception e) {
		// TODO: handle exception
		
	}
	}

	View createFooterM(String text) {
		View v = getLayoutInflater().inflate(R.layout.foterprice, null);
		((TextView)v.findViewById(R.id.san_phone)).setText(text);
		return v;      
	}
	
	View createHeaderM(String text) {
		View v = getLayoutInflater().inflate(R.layout.headerprice, null);
		((TextView)v.findViewById(R.id.tpView2)).setText(text);
		
		
		return v;      
	}
	public void listprice_() {
try {
			
			XmlPullParserFactory parserxmlpull = XmlPullParserFactory.newInstance();
			parserxmlpull.setValidating(false);
			parserxml = parserxmlpull.newPullParser();
			File xmlfileprices = new File(spprisepathfull);
			xmlfiles = new FileInputStream(xmlfileprices);
			parserxml.setInput(xmlfiles, null);
			

			groupa1 = "";
			i = 0;
			k = 0;

			groupData = new ArrayList<HashMap<String, String>>();
			childData = new ArrayList<ArrayList<HashMap<String, String>>>();
			childDataItem = new ArrayList<HashMap<String, String>>();
			
			while (parserxml.getEventType()!= XmlPullParser.END_DOCUMENT) {
				
				if (parserxml.getEventType() == XmlPullParser.START_TAG
						&& parserxml.getName().equals(iid_name + "_short") 
						&& parserxml.getDepth() == 3) {
					str_san_map = parserxml.getAttributeValue(1);
					str_san_phone = parserxml.getAttributeValue(2);
					
				}

				if (parserxml.getEventType() == XmlPullParser.START_TAG
						&& parserxml.getName().equals(iid_name + "_period") 
						&& parserxml.getDepth() == 3) {
					sanprice_period = parserxml.getAttributeValue(0);	
				}
				if (parserxml.getEventType() == XmlPullParser.START_TAG
						&& parserxml.getName().equals(iid_name) 
						&& parserxml.getDepth() == 3) {
					///

					groupa2 = parserxml.getAttributeValue(0);
					if (!groupa1.equals(groupa2)) {


						n = new HashMap<String, String>();
						n.put("groupName", parserxml.getAttributeValue(0)); 
						groupData.add(n); 
						groupa1 = parserxml.getAttributeValue(0);
						k = 1; 
						if (i==0){

							childData = new ArrayList<ArrayList<HashMap<String, String>>>(); 
							i=1;
						}

						childDataItem = new ArrayList<HashMap<String, String>>();

					}
					//


					m = new HashMap<String, String>();

					msp_0 = ssanatori_name;
					msp_0_0 = iid_name;
					msp_1 = parserxml.getAttributeValue(0);
					if (msp_1 == null) {
						msp_1 = "";
					}
					msp_2 = parserxml.getAttributeValue(1);
					if (msp_2 == null) {
						msp_2 = "";
					}
					msp_3 = parserxml.getAttributeValue(2);
					if (msp_3 == null) {
						msp_3 = "";
					}
					msp_4 = parserxml.getAttributeValue(3);
					if (msp_4 == null) {
						msp_4 = "";
					}
					msp_5 = parserxml.getAttributeValue(4);
					if (msp_5 == null) {
						msp_5 = "";
					}
					msp_6 = parserxml.getAttributeValue(5);
					if (msp_6 == null) {
						msp_6 = "";
					}
					m.put("col_0", msp_0);
					m.put("col_0_0", msp_0_0);
					m.put("col_1", parserxml.getAttributeValue(0));
					m.put("col_2", parserxml.getAttributeValue(1));                    
					m.put("col_3", parserxml.getAttributeValue(2));
					m.put("col_4", parserxml.getAttributeValue(3));
					m.put("col_5", parserxml.getAttributeValue(4));
					m.put("col_6", parserxml.getAttributeValue(5));
					m.put("col_7", parserxml.nextText());

					childDataItem.add(m);
					if (msp_1.equals(mpp_1)) {
						if (msp_2.equals(mpp_2)) {
							if (msp_3.equals(mpp_3)) {
								if (msp_4.equals(mpp_4)) {
									if (msp_5.equals(mpp_5)) {
										if (msp_6.equals(mpp_6)) {
											indexGX = groupData.size();
											if (indexGX == 0) {
												indexGXs = 0;
											} else {
												indexGXs = indexGX-1;
											}
											indexIX = childDataItem.size();
											if (indexIX == 0) {
												indexIXs = 0;
											} else {
												indexIXs = indexIX-1;
											}											
										}
									}
								}
							}
						}
					}

					if (k==1) {                     	 
						childData.add(childDataItem);
						
						k=0;
					}

					// 
				}


				parserxml.next();

			}


			xmlfiles.close(); 

			String groupFrom[] = new String[] {"groupName"};

			//int groupTo[] = new int[] {R.id.textg1};


			//String childFrom[] = new String[] {"col_1","col_2","col_3","col_4","col_5","col_6","col_7"};

			//int childTo[] = new int[] {R.id.textView_category,R.id.textView_area_n,R.id.textView_razm,R.id.textView_time,R.id.textView_food,R.id.textView_price,R.id.textView_prim};
			
			MyAdapterpr = new PriceAdapter(getApplicationContext(), groupData, childData, ssanatori_name);
			MyAdapterpr.notifyDataSetChanged();
			/*adapterpr = new SimpleExpandableListAdapter(
					getApplicationContext(),
					groupData,
					R.layout.simple_expandable_list_item_1_my,
					groupFrom,
					groupTo,
					childData,
					R.layout.items_list,
					childFrom,
					childTo);
			*/		

			//////

			listt = (ExpandableListView) findViewById(R.id.listt);
			
			Header1 = createHeaderM("");
			listt.addHeaderView(Header1);					       
			TextView headerTextView = (TextView)findViewById(R.id.tpView2);
			if (groupData.size() == 0) {
				headerTextView.setText("");
				headerTextView.setVisibility(View.GONE);
			} else {
				headerTextView.setVisibility(View.VISIBLE);
				headerTextView.setText(sanprice_period);				
			}

			Footer1 = createFooterM("");
			listt.addFooterView(Footer1);

		
			///
			footersan_phone = (TextView)findViewById(R.id.san_phone);
			footersan_phone_d = (View)findViewById(R.id.san_phone_d);
			if (str_san_phone == null) {
				str_san_phone = "";
			}
			if (!str_san_phone.equals("")) {
				footersan_phone.setVisibility(View.VISIBLE);
				footersan_phone_d.setVisibility(View.VISIBLE);
				footersan_phone.setText(str_san_phone);
			}
			///
			footersan_map = (TextView)findViewById(R.id.san_map);
			footersan_map_d = (View)findViewById(R.id.san_map_d);
			if (str_san_map == null) {
				str_san_map = "";
			}
			if (!str_san_map.equals("")) {
				footersan_map.setVisibility(View.VISIBLE);
				footersan_map_d.setVisibility(View.VISIBLE);
			}
			///
			    
			listt.setOnChildClickListener(new OnChildClickListener() { 
				@Override
				public boolean onChildClick(ExpandableListView parent, View v,
						int groupPosition, int childPosition, long id) {

					gpos = groupPosition;
					childpos = childPosition;
					flaglockother = 1;
					viewitem = v;
					GoSravFavor();
					
					return false;					
				} 
			});
			MyAdapterpr.notifyDataSetChanged();
			
				listt.setAdapter(MyAdapterpr);
			
			//adapterpr.notifyDataSetChanged();
			//listt.setAdapter(adapterpr);
			if (flags_srav == 1) {
				
				listt.expandGroup(indexGXs);
				listt.setSelectedChild(indexGXs, indexIXs, true);
				
			}
			
			if (!str_san_map.equals("")) {
				footersan_map = (TextView)findViewById(R.id.san_map);
				footersan_map.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						try {					
							Uri geo = Uri.parse(str_san_map);
							Intent geoMap = new Intent(Intent.ACTION_VIEW, geo);
							startActivity(geoMap);					
						} catch (Exception e) {
		
						}
		
					}	
				});
			}
			
		}
		catch (Exception t) {
			
		}	
	}
	public void listpriceHandler() {
		Handler handlerListTrash = new Handler();
		handlerListTrash.post(new Runnable() {
			@Override
			public void run() {				
				listprice_();
			
			}
			
		});
	}

	public boolean onCreateOptionsMenu(Menu menu) { 

		getMenuInflater().inflate(R.menu.pmenu, menu);

		return true;
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		if (FlagOnlain == 0) {
			menu.findItem(R.id.loaditem1).setVisible(true);
			menu.findItem(R.id.loaditem1).setEnabled(true);
			} else
			{			
			menu.findItem(R.id.loaditem1).setEnabled(false);
			menu.findItem(R.id.loaditem1).setVisible(false);
			}
			menu.findItem(R.id.pitem2).setEnabled(true);
			menu.findItem(R.id.abitem3).setEnabled(true);	
		return super.onPrepareOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) { 

		case R.id.loaditem1: 

			GoMain();
			break; 



		case R.id.pitem2:

			try {
				Intent Preferintent = new Intent(getApplicationContext(),PreferActivity.class);
				Preferintent.putExtra("FlagOnlain", FlagOnlain);
				startActivityForResult(Preferintent, 0);
			} catch (Exception e) {

			}
			break; 
		case R.id.abitem3: 

			try {
				Intent intentapp = new Intent(getApplicationContext(), Aboutapp.class);
				intentapp.putExtra("FlagOnlain", FlagOnlain);
				startActivityForResult(intentapp, 0);
			} catch (Exception e) {

			}
			break;
		}          


		return super.onOptionsItemSelected(item); 

	}
	private void GoMain() {
		AlertDialog.Builder buildergomain = new AlertDialog.Builder(this);
		buildergomain.setTitle(R.string.lt_app);		
		buildergomain.setMessage(R.string.lmmm_app);		
		buildergomain.setNegativeButton(R.string.qn_app, null);
		buildergomain.setPositiveButton(R.string.qy_app, new OnClickListener() {
			public void onClick(DialogInterface arg0, int arg1) {
				setResult(7);
				finish(); 	            	

			}
		}).create().show();	
	}

	private void GoSravFavor() {
		final ArrayList<HashMap<String, String>>  chData = childData.get(gpos);
		final String pfavor_category = chData.get(childpos).get("col_1").toString();
		final String pfavor_area_n = chData.get(childpos).get("col_2").toString();
		final String pfavor_razm = chData.get(childpos).get("col_3").toString();
		final String pfavor_time = chData.get(childpos).get("col_4").toString();
		final String pfavor_food = chData.get(childpos).get("col_5").toString();
		final String pfavor_price = chData.get(childpos).get("col_6").toString();
		final String pfavor_prim = chData.get(childpos).get("col_7").toString();
		final String description_calendar = ssanatori_name+" / " + chData.get(childpos).get("col_1").toString()+ " / " +
				chData.get(childpos).get("col_2").toString()+" / " + chData.get(childpos).get("col_3").toString()+" / " + chData.get(childpos).get("col_4").toString()+" / " +
				chData.get(childpos).get("col_5").toString()+" (" +chData.get(childpos).get("col_7").toString() + ") "+
				" ....... " + chData.get(childpos).get("col_6").toString() +" "+getString(R.string.hotel_prise);
		buildergosrav = new AlertDialog.Builder(this);
		buildergosrav.setTitle("");		
		buildergosrav.setItems(spisok, 
			new DialogInterface.OnClickListener() {
							
			@Override
			public void onClick(DialogInterface dialog, int item) {
				switch (item) { 

				case 0:
						
					try {
						Intent intentsea = new Intent(getApplicationContext(), Sravneniye.class);
						Integer flags_srav = 2;
						intentsea.putExtra("flags_srav", flags_srav);
						if (groupData.size() >0) {
						intentsea.putExtra("san_name", ssanatori_name);
						intentsea.putExtra("id_name", iid_name);
						intentsea.putExtra("spprisepath", spprisepath);
						intentsea.putExtra("spprisepathfull", spprisepathfull);
						intentsea.putExtra("FlagOnlain", FlagOnlain);
						intentsea.putExtra("gpos", gpos);
						intentsea.putExtra("childpos", childpos);					
						startActivityForResult(intentsea,3);
						}
					} catch (Exception e) {

					}
				break;
				
				case 1:
					
					try {
						
						
						PriceAdapter MyAdapterpr_ = new PriceAdapter(getApplicationContext(), groupData, childData, ssanatori_name);
						
						if (MyAdapterpr_.countf(gpos, childpos, ssanatori_name) > 0) {
							Toast.makeText(getApplicationContext(),getString(R.string.f_add_no).toString(),Toast.LENGTH_LONG ).show();
						} else {
							//insert item in favorits
							Favorsql sqlinsert = new Favorsql(getApplicationContext());
					     	// ���� ������ � ������
							SQLiteDatabase sqldb_insert = sqlinsert.getWritableDatabase();
							String sqlinserttext = "INSERT INTO " + Favorsql.dtable + 
								     " (" + Favorsql.DFAVORSAN + "," + Favorsql.DFAVORCATEGORY + "," + Favorsql.DFAVORAREAN +
								     "," + Favorsql.DFAVORRAZM + "," + Favorsql.DFAVORTIME + "," + Favorsql.DFAVORFOOD + "," + Favorsql.DFAVORPRICE + "," + Favorsql.DFAVORPRIM +
								     ") VALUES ('" + ssanatori_name + "','" + pfavor_category + "','" + pfavor_area_n + 
								     "','" + pfavor_razm + "','" + pfavor_time + "','" + pfavor_food + "','" + pfavor_price + "','" + pfavor_prim +
								     "')";
							
							sqldb_insert.execSQL(sqlinserttext);
							MyAdapterpr_.viewfavorit(viewitem,gpos, childpos);
							sqldb_insert.close();
							sqlinsert.close();
							Toast.makeText(getApplicationContext(),getString(R.string.f_add).toString(),Toast.LENGTH_LONG ).show();
						}					
						
					} catch (Exception e) {
						
					}
				break;
				case 2:
					try { 
						
						Intent calendarIntent = new Intent(Intent.ACTION_INSERT);
						calendarIntent.setType("vnd.android.cursor.item/event"); 
						calendarIntent.putExtra(Events.TITLE, getString(R.string.calend_title));
						calendarIntent.putExtra(Events.EVENT_LOCATION, ssanatori_name + " "+ getString(R.string.location));
						calendarIntent.putExtra(Events.DESCRIPTION, description_calendar);					                 
		                calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true); 
		                calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,System.currentTimeMillis()); 
		                calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,System.currentTimeMillis()); 
		                startActivity(calendarIntent);				
					} catch (Exception e) {

					}
				break;
				case 3:
					try {			
						//
						Intent sendIntent = new Intent();
						sendIntent.setAction(Intent.ACTION_SEND);
						sendIntent.putExtra(Intent.EXTRA_TEXT, description_calendar);
						sendIntent.setType("text/plain");
						startActivity(sendIntent);
						//
					} catch (Exception e) {

					}
				break;
				}
			}
		}				
				).create().show();


	}
	public void Dopmenu() {
		dialogdopmenu = new AlertDialog.Builder(this);
		dialogdopmenu.setTitle("");		
		dialogdopmenu.setItems(dopmenu, 
				new DialogInterface.OnClickListener() {					
			@Override
			public void onClick(DialogInterface dialog, int which) {
				try { 
					openOptionsMenu();				
				} catch (Exception e) {
	
				}						
		}
	}				
			).create().show();


}
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState); 		
		flaglockother = savedInstanceState.getInt("flaglockother");
	} 

	protected void onSaveInstanceState(Bundle outState) { 
		super.onSaveInstanceState(outState);		
			outState.putInt("flaglockother", flaglockother);	
		
	} 

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == 2) {
			MyAdapterpr.notifyDataSetChanged();
			//adapterpr.notifyDataSetChanged();
		}
		if (resultCode == 3) {
			
			
			finish();
		}
		if (resultCode == 7) {
			
			
			setResult(7);

			finish();
		}

		if (resultCode ==  5) {
			try {
				openOptionsMenu();
			} catch (Exception e) {

			}
		}
		if (resultCode ==  9) {
			try {
				Intent Preferintent = new Intent(getApplicationContext(),PreferActivity.class);
				Preferintent.putExtra("FlagOnlain", FlagOnlain);
				startActivityForResult(Preferintent,0);	
			} catch (Exception e) {

			}
		}
		if (resultCode ==  10) {	
			try {
				Intent intentapp = new Intent(getApplicationContext(), Aboutapp.class);
				intentapp.putExtra("FlagOnlain", FlagOnlain);
				startActivityForResult(intentapp,0);
			} catch (Exception e) {

			}
		}

	}


}
